<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="info" />
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <MyPatient
          v-for="item in  arr"
          :key="item.id"
          :date="item.date"
          :uname="item.uname"
          :ensue="item.ensue"
          :recipe="item.recipe"
        ></MyPatient>
      </tbody>
    </table>
  </div>
</template>

<script>
import MyPatient from './components/MyPatient.vue';
export default {
  components: {
    MyPatient,
  },
  data() {
    return {
      arr: [
        {
          id: '1',
          uname: '张三',
          ensue: '感冒',
          recipe: '感冒药',
          date: '2020-12-01',
        },
        {
          id: '2',
          uname: '李四',
          ensue: '头疼',
          recipe: '止疼药',
          date: '2020-12-01',
        },
        {
          id: '3',
          uname: '王二',
          ensue: '腰痛',
          recipe: '止痛贴',
          date: '2020-12-01',
        },
      ],
      info: '',
      newArr: '',
    };
  },
  computed:{
   infoArray(){
      return this.arr.filter(item =>{
        return item.uname === this.info || 
        item.ensue === this.info || 
        item.recipe === this.info ||
        item.date === this.info  })
    }
  }
  // watch: {
  //   info(value) {
  //     if (this.arr.some((item) => item.uname === value)) {
  //       this.newArr = this.arr;
  //       this.arr = this.arr.filter((item) => item.uname === value);
  //     } else {
  //       if (this.newArr) {
  //         this.arr = this.newArr;
  //       }
  //     }
  //   },
  // },
};
</script>

<style scoped>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
